import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.DropMode;
import java.awt.Color;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.text.ParseException;
import java.util.GregorianCalendar;
import javax.swing.JOptionPane;
import java.awt.Font;
import javax.swing.JFormattedTextField;
import javax.swing.text.MaskFormatter;
import javax.swing.JSeparator;

public class VueNouvSociete extends Vue {

	/**
	 * 
	 */
	//private static final long serialVersionUID = 5069349224425178639L;
	private JPanel contentPane;
	private JTextField textFieldNom;
	private JTextField textFieldPrenom;
	
	// pour que les boutons soient des attributs, il faut faire "convert local to field"
	private JButton btnEnregistrer;
	private JButton btnAnnuler;

	// a ajouter car la vue est observatrice d'un client
	private ClientPhysique _client ;
	private JTextField textNumS;
	private JLabel label;
	private JLabel label_1;
	private JTextField textAdresseS;
	private JLabel label_2;
	private JTextField textNomSociete;
	
	/**
	 * Create the frame.
	 * @throws ParseException 
	 */
	public VueNouvSociete(Controleur controleur) throws ParseException {
		super (controleur);
		setTitle("Enregistrement d'une nouvelle Société");
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 600, 370);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblNom = new JLabel("Nom :");
		lblNom.setBounds(98, 38, 61, 16);
		contentPane.add(lblNom);
		
		textFieldNom = new JTextField();
		textFieldNom.setBounds(206, 33, 303, 28);
		textFieldNom.setBackground(new Color(255, 255, 255));
		contentPane.add(textFieldNom);
		textFieldNom.setColumns(10);
		
		btnEnregistrer = new JButton("Enregistrer");
		btnEnregistrer.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String nom = textFieldNom.getText().trim().toLowerCase();
				String prenom = textFieldPrenom.getText().trim().toLowerCase();
				String nomSociete = textNomSociete.getText().trim().toLowerCase();
				String numS = textNumS.getText().trim();
				String adresseS = textAdresseS.getText().trim().toLowerCase();
				getControleur().nouvSociete(nom, prenom, nomSociete, numS, adresseS);}
		});
		btnEnregistrer.setBounds(302, 306, 117, 29);
		contentPane.add(btnEnregistrer);
		
		btnAnnuler = new JButton("Annuler");
		btnAnnuler.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				getControleur().fermerVue(VueNouvSociete.this);
			}
		});
		btnAnnuler.setBounds(173, 306, 117, 29);
		contentPane.add(btnAnnuler);
		
		JLabel lblPrnom = new JLabel("Prénom :");
		lblPrnom.setBounds(98, 94, 61, 16);
		contentPane.add(lblPrnom);
		
		textFieldPrenom = new JTextField();
		textFieldPrenom.setBounds(206, 89, 303, 28);
		contentPane.add(textFieldPrenom);
		textFieldPrenom.setColumns(10);
		
		textNumS = new JTextField();
		textNumS.setColumns(10);
		textNumS.setBackground(Color.WHITE);
		textNumS.setBounds(272, 218, 235, 28);
		contentPane.add(textNumS);
		
		label = new JLabel("Numéro SIREN :");
		label.setBounds(96, 221, 119, 20);
		contentPane.add(label);
		
		label_1 = new JLabel("Adresse de la société:");
		label_1.setBounds(96, 260, 140, 34);
		contentPane.add(label_1);
		
		textAdresseS = new JTextField();
		textAdresseS.setColumns(10);
		textAdresseS.setBounds(272, 264, 235, 28);
		contentPane.add(textAdresseS);
		
		label_2 = new JLabel("Nom de la société:");
		label_2.setBounds(96, 174, 119, 16);
		contentPane.add(label_2);
		
		JSeparator separator = new JSeparator();
		separator.setBounds(14, 135, 570, 3);
		contentPane.add(separator);
		
		JLabel lblTitulaireDuCompte = new JLabel("Titulaire du Compte");
		lblTitulaireDuCompte.setBounds(14, 8, 130, 17);
		contentPane.add(lblTitulaireDuCompte);
		
		JLabel lblInfosSocit = new JLabel("Infos Société");
		lblInfosSocit.setBounds(14, 143, 88, 16);
		contentPane.add(lblInfosSocit);
		
		textNomSociete = new JTextField();
		textNomSociete.setBounds(272, 169, 235, 28);
		contentPane.add(textNomSociete);
		textNomSociete.setColumns(10);
	}
	
	public void setEtat (int etat){
		switch (etat) {
		case initiale: {
			btnEnregistrer.setEnabled(true);
			btnAnnuler.setEnabled(true);
			break;
			}
		}
	}
}
